package com.epigeon.amadeo.impl;

import com.epigeon.amadeo.model.Message;
import com.epigeon.amadeo.model.StringMessage;
import com.epigeon.amadeo.modifier.Modifier;

public class ReverseStringModifier implements Modifier {

	@Override
	public Message modify(Message message) throws IllegalArgumentException {
		
		if ( message instanceof StringMessage == false ) {
			throw new IllegalArgumentException("message is not of type StringMessage");
		}
		
		StringMessage smessage = (StringMessage) message;
		StringBuffer sbuf = new StringBuffer(smessage.getValue());
		sbuf.reverse();
		
		return new StringMessage(smessage.getType(), message.getSourceKey(), sbuf.toString());
	}
	
}
